package org.example.util;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PageUtil {

    public static <T> Map<String, Object>  ListPage(int page, int size, List<T> data){
        Map<String, Object> result = new HashMap<>();
        int totalRecords = data.size();
        int total = (int) Math.ceil((double) totalRecords / size);
        List<T> records = data.subList((page - 1) * size, Math.min(page * size, totalRecords));
        result.put("size", size);
        result.put("page", page);
        result.put("total", total);
        result.put("records", records);
        return result;
    }
}
